<!--<template>-->
<!--  <div class="sidebar">-->
<!--    <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse"-->
<!--             background-color="#324157" text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router-->
<!--    >-->
<!--      <template v-for="item in routers">-->
<!--        <template v-if="item.children">-->
<!--          &lt;!&ndash;                  属性 index :就是 菜单对应的路由&ndash;&gt;-->
<!--          <el-submenu :index="item.path" :key="item.name">-->
<!--            <template #title>-->
<!--              <i :class="item.meta.icon"></i>-->
<!--              <span>{{ item.meta.title }}</span>-->
<!--            </template>-->
<!--            <template v-for="subItem in item.children">-->
<!--              <el-submenu v-if="subItem.children" :index="subItem.path" :key="subItem.name">-->
<!--                <template #title>{{ subItem.meta.title }}</template>-->
<!--                <el-menu-item v-for="(threeItem, i) in subItem.children" :key="i" :index="threeItem.path">-->
<!--                  {{ threeItem.meta.title }}-->
<!--                </el-menu-item>-->
<!--              </el-submenu>-->
<!--              <el-menu-item v-else :index="subItem.path" :key="subItem.name">-->
<!--                {{ subItem.meta.title }}-->
<!--              </el-menu-item>-->
<!--            </template>-->
<!--          </el-submenu>-->
<!--        </template>-->
<!--        <template v-else>-->
<!--          <el-menu-item :index="item.path" :key="item.name">-->
<!--            <i :class="item.meta.icon"></i>-->
<!--            <template #title>{{ item.meta.title }}</template>-->
<!--          </el-menu-item>-->
<!--        </template>-->
<!--      </template>-->
<!--    </el-menu>-->
<!--  </div>-->
<!--</template>-->

<template>
  <div class="sidebar">
    <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
             text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
      <template v-for="item in routers">
        <template v-if="item.children">
          <el-sub-menu :index="item.path" :key="item.name">
            <template #title>
              <span>{{ item.meta.title }}</span>
            </template>
            <el-menu-item v-for="subItem in item.children" :index="subItem.path" :key="subItem.name">
              <span>{{ subItem.meta.title }}</span>
            </el-menu-item>
          </el-sub-menu>
        </template>
        <template v-else>
          <el-menu-item :index="item.path" :key="item.name">
            <span>{{ item.meta.title }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
import {mapState} from 'vuex'

export default {
  data() {
    return {};
  },
  computed: {
    ...mapState([
      'collapse',
      'routers'
    ]),
    onRoutes() {
      return this.$route.path.replace("/", "");
    }
  }
};
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}

.sidebar::-webkit-scrollbar {
  width: 0;
}

.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}

.sidebar > ul {
  height: 100%;
}
</style>
